var selectedDataRow = '';
var vueObj = new Vue({
    el: "#vue",
    data: {
        logObj: defLogInfo
    }
});
var isInit = true;

$(function () {
    window.actionEvents = {
        'click .isvInfoView': function(e, value, row, index) {
            //编辑操作
            selectedDataRow = row;
            openCommonIsvPage(row.isvPid, 'checkBizDocApp');
        },
    }
    initTextSearch("#isvName",
        basePath + 'checkBizDocApp/getIsvData?t='+new Date().getTime()+'&isvName=',
        ['isvPid', 'isvName'],
        {'isvPid':'服务商PID', 'isvName':'服务商名称'},
        'isvPid',
        'isvName',
        true,
        selectIsvValue,
        noSelectIsvValue,
        false);
    initTextSearch("#orgName",
        basePath + 'checkBizDocApp/getOrgData?t='+new Date().getTime()+'&orgName=',
        ['orgCode', 'orgName'],
        {'orgCode':'机构编码', 'orgName':'机构名称'},
        'orgCode',
        'orgName',
        true,
        selectOrgValue,
        noSelectOrgValue,
        false);
    /*laydate.render({
        elem: '#beginTimeStr'
        ,done: function(value, date, endDate){
            //控件选择完毕后的回调
            //点击日期、清空、现在、确定均会触发。回调返回三个参数，分别代表：生成的值、日期时间对象、结束的日期时间对象
            // setAge(value);
        }
    });*/
    laydate.render({
        elem: '#timeInterval'
        ,type: 'datetime'
        ,range: true //或 range: '~' 来自定义分割字符
        // ,value: dateFtt("yyyy-MM-dd hh:mm:ss", preDate) + ' - ' + dateFtt("yyyy-MM-dd hh:mm:ss", curDate)
        //js赋值重置失效，改为就是怕、页面赋值
        ,isInitValue: true //是否允许填充初始值，默认为 true
    });
});

function selectIsvValue(data) {
    if (!data || !data.isvPid) {
        return;
    }
    $('#isvPid').val(data.isvPid);
}

function noSelectIsvValue() {
    $('#isvPid').val('');
}

function selectOrgValue(data) {
    if (!data || !data.orgCode) {
        return;
    }
    $('#orgCode').val(data.orgCode);
}

function noSelectOrgValue() {
    $('#orgCode').val('');
}

function doRefresh() {
    selectedDataRow = '';
    var docName = $('#docName').val();
    var checkType = $('#checkType').val();
    var orgCode = $('#orgCode').val();
    var bizCode = $('#bizCode').val();
    var isvPid = $('#isvPid').val();
    // var beginTimeStr = $('#beginTimeStr').val();
    var gmtStart = '';
    var gmtEnd = '';
    var timeInterval = $("#timeInterval").val();
    if(timeInterval){
        var dates = timeInterval.split(' - ');
        if(dates && dates.length >1){
            gmtStart = dates[0];
            gmtEnd = dates[1];
        }
    }
    $('#dataTable').bootstrapTable('refresh', {
        url: basePath + 'checkBizDocApp/pageFindCheckData?t=' + new Date().getTime(),
        query: {
            docName : docName,
            checkType : checkType,
            orgCode : orgCode,
            bizCode : bizCode,
            isvPid : isvPid,
            beginTimeStr : gmtStart,
            endTimeStr : gmtEnd,
        },
    });
}

function getParams(params) {
    var docName = $('#docName').val();
    var checkType = $('#checkType').val();
    var orgCode = $('#orgCode').val();
    var bizCode = $('#bizCode').val();
    var isvPid = $('#isvPid').val();
    // var beginTimeStr = $('#beginTimeStr').val();
    var gmtStart = '';
    var gmtEnd = '';
    var timeInterval = $("#timeInterval").val();
    if(timeInterval){
        var dates = timeInterval.split(' - ');
        if(dates && dates.length >1){
            gmtStart = dates[0];
            gmtEnd = dates[1];
        }
    }
    var pageNo = params.pageNumber;
    var pageSize = params.pageSize;
    if (isInit) {
        isInit = false;
        pageSize = defLogInfo.pageSize ? defLogInfo.pageSize : params.pageSize;
        pageNo = defLogInfo.pageNo ? defLogInfo.pageNo : params.pageNumber;
    }
    return {
        docName : docName,
        checkType : checkType,
        orgCode : orgCode,
        bizCode : bizCode,
        isvPid : isvPid,
        beginTimeStr : gmtStart,
        endTimeStr : gmtEnd,
        pageSize : pageSize,
        pageNo : pageNo
    };
}

function openCheckPage() {
    if (!selectedDataRow || selectedDataRow == '') {
        toastr.error(common_no_choose_msg.format("审核"));
        return;
    }
    var tableOptions = $('#dataTable').bootstrapTable('getOptions', null);
    window.location.href = basePath + 'checkBizDocApp/checkBizDocAppInfoPage?&id=' + selectedDataRow.id +
        '&batchId=' + selectedDataRow.batchId + '&type=check&t=' + new Date().getTime() + '&isQueryExist=' + defLogInfo.isQueryExist +
        '&' + $('#searchForm').serialize() + '&pageNo=' + tableOptions.pageNumber + '&pageSize=' + tableOptions.pageSize;
}

//------------------------------------------------------------------------列表数据初始化

function formatCheckType(value, row, index) {
    if (checkTypeList) {
        for (var i=0; i<checkTypeList.length; i++) {
            if (value == checkTypeList[i].key) {
                return checkTypeList[i].value;
            }
        }
    }
    return value;
}

//------------------------------------------------------------------------列表选中事件
//上边选中事件
$("#dataTable").on("click-row.bs.table",function(e,row,ele){
    $("#dataTable .success").removeClass("success");
    $(ele).addClass("success");
    selectedDataRow = row;
});
